home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11892 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.0 KB

  1. Path: pop.gnn.com!HoangTQ
  2. From: Tuyen Hoang <HoangTQ@gnn.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Need Help With CSC Homework
  5. Date: Sat, 16 Mar 1996 17:26:03
  6. Organization: GNN
  7. Message-ID: <4iff2c$p2i@news-e2b.gnn.com>
  8. References: <4g0qq4$o0@news.nevada.edu>
  9. NNTP-Posting-Host: www-41-87.gnn.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset="us-ascii"
  12. X-GNN-NewsServer-Posting-Date: 16 Mar 1996 22:24:12 GMT
  13. X-Mailer: GNNmessenger 1.2
  14.  
  15. Dear Troy
  16.  
  17. I found some serious error in your code, and you might want to look at my 
  18. comment in the pfun.c file
  19.  
  20. There are serious problems in your algorithm, too.  You use an char array[21]
  21. for store the Roman number, so the greatest number is 20,000(20 letters M). 
  22. How about the next one? 19,999? No, it's 19,500(19 letters M and 1 for D)
  23. those numbers from 19,501 to 19,999 are *out* of your hand. There are more, 
  24. 19,100(19 letters M and 1 for C) is ok, but those numbers from 19,101 to 
  25. 19,499 are all gone. I don't have the patient to count all of them, but at 
  26. least, I do know the problem begins at 9,888(MMM MMM MMM DCCC LXXX VIII : 21 
  27. letters). Do I surprise you?
  28.  
  29. The second problem is that there are NO Roman number IIII or VIIII as you try 
  30. to implement, as I know number four is IV and number 9 is IX, ect.
  31. Suppose that your implement is acceptable, so you jump in to trouble at 6,999 
  32. (MMM MMM DCCCC LXXXX VIIII : 21 letter) much earlier than the ancient Romans 
  33. did.
  34.  
  35. Increase the value of MAXLENGTH won't solve this problem, the correct 
  36. solution is using dynamic allocation: allocate the char* after calculate it 
  37. length.
  38.  
  39. If you want a hasty solution, I have it handy: the value range for type 
  40. unsigned int is from 0 to 65,xxx(for Turbo C), therefore for your Roman 
  41. number's safety, you should set MAXLENGTH to 65+15+1 = 81. If you want to use 
  42. long instead, you should increase MAXLENGTH accordingly.
  43. If I were you, I would rewiew the algorithm and rewrite the whole thing 
  44. again. I don't know if you have time to do it again. So good luck.
  45.  
  46. Tuyen Hoang.
  47.  
  48.